package edu.ntu.im.p2ptrade.msg.handle;

import java.util.List;

import net.jxta.endpoint.Message;
import edu.ntu.im.p2ptrade.P2PTrade;
import edu.ntu.im.p2ptrade.entity.Item;
import edu.ntu.im.p2ptrade.metadata.MetaDataSearcher;
import edu.ntu.im.p2ptrade.msg.PMessage;
import edu.ntu.im.p2ptrade.msg.SearchItemQuery;

public class SearchResultHandle implements PMessageHandle {

	public void handle(Message msg) {
		String peer = msg.getMessageElement(P2PTrade.getInstance().getAppName(), PMessage.PEER).toString();
		String query = msg.getMessageElement(P2PTrade.getInstance().getAppName(), SearchItemQuery.QUERY).toString();
		List<Item> items = MyItemHandle.msg2Items(msg, peer);
		
		MetaDataSearcher.recieveResult(query,items);

	}

}
